package com.flyduck.vueshop.user.remote.controller;

import com.flyduck.vueshop.common.core.lang.Result;
import com.flyduck.vueshop.common.sotoken.annotation.InnerAuth;
import com.flyduck.vueshop.user.remote.service.RemoteUserService;
import com.flyduck.vueshop.user.vo.RemoteUserRespVO;
import com.flyduck.vueshop.user.vo.RemoteUserSaveReqVO;
import com.flyduck.vueshop.user.vo.RemoteUserUpdateReqVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * AppUserApiController
 * </p>
 *
 * @author flyduck
 * @since 2024-07-10
 */
@RestController
@RequestMapping("/user/remote/user")
public class RemoteUserController {

    @Resource
    private RemoteUserService remoteUserService;

    @InnerAuth
    @GetMapping("/getUserByUsername")
    Result<RemoteUserRespVO> getUserByUsername(@RequestParam("username") String username){
        RemoteUserRespVO remoteUserRespVO = remoteUserService.getUserByUsername(username);
        return Result.success(remoteUserRespVO);
    }

    @InnerAuth
    @GetMapping("/getUserById/{id}")
    public Result<RemoteUserRespVO> getUserById(@PathVariable("id") Long id){
        RemoteUserRespVO remoteUserRespVO = remoteUserService.getUserById(id);
        return Result.success(remoteUserRespVO);
    }

    @InnerAuth
    @PostMapping("/saveUser")
    Result<Void> saveUser(@RequestBody RemoteUserSaveReqVO remoteUserSaveReqVO){
        remoteUserService.saveUser(remoteUserSaveReqVO);
        return Result.success();
    }

    @InnerAuth
    @PostMapping("/updateUser")
    Result<Void> updateUser(@RequestBody RemoteUserUpdateReqVO remoteUserUpdateReqVO){
        remoteUserService.updateUser(remoteUserUpdateReqVO);
        return Result.success();
    }
}
